package com.iims.flowable.flow.vo;

import com.iims.common.core.page.PageDomain;
import com.iims.flowable.flow.ObjectUtils;
import com.iims.flowable.flow.vo.request.IBaseQueryVo;
import lombok.Data;
import org.flowable.common.engine.api.query.Query;
import org.flowable.engine.repository.ModelQuery;

@Data
public class ModelQueryVo extends PageDomain implements IBaseQueryVo<ModelQuery> {
    private String modelId;
    private String modelCategory;
    private String modelName;
    private String modelKey;
    private Integer modelVersion;
    private Boolean latestVersion = false;
    private Boolean deployed;
    private String deploymentId;
    private String tenantId;

    @Override
    public Query genSearchQuery(ModelQuery query) {
        if (ObjectUtils.isNotEmpty(this.getModelId())) {
            query.modelId(this.getModelId());
        }
        if (ObjectUtils.isNotEmpty(this.getModelCategory())) {
            query.modelCategoryLike(ObjectUtils.convertToLike(this.getModelCategory()));
        }
        if (ObjectUtils.isNotEmpty(this.getModelName())) {
            query.modelNameLike(this.getModelName());
        }
        if (ObjectUtils.isNotEmpty(this.getModelKey())) {
            query.modelKey(this.getModelKey());
        }
        if (ObjectUtils.isNotEmpty(this.getModelVersion())) {
            query.modelVersion(this.getModelVersion());
        }
        if (this.getLatestVersion() != null) {
            if (this.getLatestVersion()) {
                query.latestVersion();
            }
        }
        if (ObjectUtils.isNotEmpty(this.getDeploymentId())) {
            query.deploymentId(this.getDeploymentId());
        }
        if (this.getDeployed() != null) {
            if (this.getDeployed()) {
                query.deployed();
            } else {
                query.notDeployed();
            }
        }
        if (ObjectUtils.isNotEmpty(this.getTenantId())) {
            query.modelTenantId(this.getTenantId());
        }
        return query;
    }

    @Override
    public PageDomain selectPageDomain() {
        return this;
    }
}
